package org.example.supplychain.mapper;

import org.apache.ibatis.annotations.*;
import org.example.supplychain.domain.Material;

import java.util.List;

@Mapper
public interface MaterialMapper {
    /**
     * 添加原料
     *
     * @param material 原料
     */
    @Insert("INSERT INTO material(material_name,supplier_name,average_unit_price) VALUES (#{materialName},#{supplierName},#{averageUnitPrice})")
    void addMaterial(Material material);

    /**
     * 删除原料
     *
     * @param materialId 原料id
     */
    @Delete("DELETE FROM material WHERE material_id = #{materialId}")
    void deleteMaterialByMaterialId(long materialId);

    /**
     * 更新原料
     *
     * @param material 原料
     */
    @Update("UPDATE material SET material_name=#{materialName},supplier_name = #{supplierName},average_unit_price = #{averageUnitPrice} WHERE material_id = #{materialId}")
    void updateMaterial(Material material);

    /**
     * 根据原料id获取原料
     *
     * @param materialId 原料id
     * @return 原料
     */
    @Select("SELECT * FROM material WHERE material_id = #{materialId}")
    Material getMaterialByMaterialId(long materialId);

    /**
     * 根据原料名和供应商名获取原料
     *
     * @param materialName 原料名
     * @return 原料
     */
    @Select("SELECT * FROM material WHERE material_name = #{materialName} AND supplier_name = #{supplierName}")
    Material getMaterialByMaterialNameAndSupplierName(String materialName,String supplierName);

    /**
     * 根据原料名获取原料
     * @param materialName
     * @return
     */
    @Select("SELECT * FROM material WHERE material_name = #{materialName}")
    List<Material> getMaterialByMaterialName(String materialName);

    /**
     * 根据供应商名获取材料
     * @param supplierName
     * @return
     */
    @Select("SELECT * FROM material WHERE supplier_name = #{supplierName}")
    List<Material> getMaterialBySupplierName(String supplierName);
}
